app.controller("index", function($scope, service, $http, $state) {

    console.log($scope.currentState);
    $scope.editData = function(data) {
        console.log(data);
        $scope.status = "edit";
        $scope.modalData = data;
        $("#modal").modal('show');
    }

    $scope.showModal = function() {
        $scope.status = "add";

        $("#modal").modal('show');
    }
})
app.controller("login", function($scope, service, $http) {
    $http({
        url: $scope.host + "/Login/index",
        method: "get",
        dataType: "json"
    }).success(function(data) {
        $scope.account = data.userAccount;
    });

    $scope.submit = function() {
        $("form").ajaxSubmit({
            type: "post",
            dataType: "json",
            url: $scope.host + "/Login/login",
            success: function(data) {
                console.log(data);
                if (data.code == 0) {
                    alert(data.msg);
                    location.href = "/views/#/home";
                } else {
                    alert(data.msg);
                }
            },
            fail: function(data) {

            }
        })
    }

})

app.controller("home", function($scope) {
    // console.log(data);
})
app.controller("profile", function($scope, service, $http, $state) {
    console.log($state.current.name);
    $scope.url = $scope.host + "News/addNews";
    if ($state.current.name == 'profile') {
        $scope.type = 7;
    } else if ($state.current.name == 'education') {
        $scope.type = 6;
    } else if ($state.current.name == 'profession') {
        // $scope.type=6;
    } else if ($state.current.name == 'education') {
        $scope.type = 6;
    } else if ($state.current.name == 'news') {
        $scope.type = 0;
    } else if ($state.current.name == 'inform') {
        $scope.type = 2;
    } else if ($state.current.name == 'student') {
        $scope.type = 1;
    } else if ($state.current.name == 'notice') {
        $scope.type = 3;
    } else if ($state.current.name == 'briefing') {
        $scope.type = 4;
        $scope.url = $scope.host + "/UploadFile/uploadFile"
    } else if ($state.current.name == 'material') {
        $scope.type = 5;
        $scope.url = $scope.host + "/UploadFile/uploadFile"
    }
    if ($state.current.name != 'apply') {
        $http({
            method: "get",
            url: $scope.host + "News/getNewsList/" + $scope.type,
            dataType: "json",
        }).success(function(data) {
            console.log(data);
            $scope.data = data;
        })
        $scope.deleteData = function(id) {
            console.log(id);
            $http({
                method: "get",
                url: $scope.host + "News/deleteNews/" + id,
                dataType: "json",
            }).success(function(data) {
                console.log(data);
                alert(data.msg);
                $state.reload();
            })
        }
    } else if ($state.current.name == 'apply') {
        $http({
            method: "get",
            url: $scope.host + "Student/getStudentEnroll",
            dataType: "json",
        }).success(function(data) {
            console.log(data);
            $scope.data = data;
        })
        $scope.deleteData = function(id) {
            $http({
                method: "get",
                url: $scope.host + "Student/deleteStudentEnroll/" + id,
                dataType: "json",
            }).success(function(data) {
                console.log(data);
                alert(data.msg);
                $state.reload();
            })
        }
    }
    $scope.topData = function(id) {
        $http({
            method: "get",
            url: $scope.host + "News/setTop/" + id + "/" + $scope.type,
            dataType: "json",
        }).success(function(data) {
            console.log(data);
            if (data.code == 0) {
                $state.reload();
            } else {
                alert(data.msg);
            }
        })
    }

})



app.controller("major", function($scope, $http, $state) {

    if ($scope.currentState == 'subject') {
        $scope.type = 1;
    } else if ($scope.currentState == 'category') {
        $scope.type = 2;
    } else if ($scope.currentState == 'major') {
        $scope.type = 3;
    }
    $http({
        method: "get",
        url: $scope.host + "BaseDatas/getExpertiseList/" +$scope.type+"/"+$state.params.page,
        url: $scope.host + "BaseDatas/getExpertiseList/" + $scope.type + "/" + $state.params.page,
        dataType: "json",
    }).success(function(data) {
        console.log(data);
        $scope.data = data;
        $scope.currentPage=data.page;
        $scope.currentPage = data.page;
    })
    $scope.deleteData = function(id) {
        $http({
            method: "get",
            url: $scope.host + "BaseDatas/deleteExpertise/" + id,
            dataType: "json",
        }).success(function(data) {
            console.log(data);
            alert(data.msg);
            $state.reload();
        })
    }
    $scope.editData = function(data) {
        $scope.status = "edit";
        $scope.modalData = data;
        $scope.url = $scope.host + "BaseDatas/modifyExpertise";
        $("#modal").modal('show');
    }
    $scope.showModal = function() {
        $scope.status = "add";
        $scope.url = $scope.host + "BaseDatas/insertExpertise";
        $("#modal").modal('show');
    }
    $scope.pageChange = function() {
        $state.go($scope.currentState, { page: $scope.currentPage })
    }

})